//$(document).ready(function(e) {
$(function() {
	loadImg();
	
	bindselect();
	
	$('#szhyfile').on('change', function() {
	      var fileNames = '';
	      $.each(this.files, function() {
	        fileNames += '<span class="am-badge">' + this.name + '</span> ';
	      });
	      var filepath = $("input[name='szhyfile']").val();
	      var extStart = filepath.lastIndexOf(".");
	      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
	          alert("图片限于bmp,png,gif,jpeg,jpg格式");
	          return false;
	      }
	      $('#szhyfile-list').html(fileNames);
	      return true;      
	    });
	
	$('#jjtpfile').on('change', function() {
	      var fileNames = '';
	      $.each(this.files, function() {
	        fileNames += '<span class="am-badge">' + this.name + '</span> ';
	      });
	      var filepath = $("input[name='jjtpfile']").val();
	      var extStart = filepath.lastIndexOf(".");
	      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
	          alert("图片限于bmp,png,gif,jpeg,jpg格式");
	          return false;
	      }
	      $('#jjtpfile-list').html(fileNames);
	      return true;      
	    });
	
	$('#file').on('change', function() {
      var fileNames = '';
      $.each(this.files, function() {
        fileNames += '<span class="am-badge">' + this.name + '</span> ';
      });
      var filepath = $("input[name='file']").val();
      var extStart = filepath.lastIndexOf(".");
      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
          alert("图片限于bmp,png,gif,jpeg,jpg格式");
          return false;
      }
      $('#file-list').html(fileNames);
      return true;      
    });
	
	$('#yyzzfile').on('change', function() {
      var fileNames = '';
      $.each(this.files, function() {
        fileNames += '<span class="am-badge">' + this.name + '</span> ';
      });
      var filepath = $("input[name='yyzzfile']").val();
      var extStart = filepath.lastIndexOf(".");
      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
          alert("图片限于bmp,png,gif,jpeg,jpg格式");
          return false;
      }
      $('#yyzzfile-list').html(fileNames);
      return true;      
    });
	
	$('#zzjgfile').on('change', function() {
      var fileNames = '';
      $.each(this.files, function() {
        fileNames += '<span class="am-badge">' + this.name + '</span> ';
      });
      var filepath = $("input[name='zzjgfile']").val();
      var extStart = filepath.lastIndexOf(".");
      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
          alert("图片限于bmp,png,gif,jpeg,jpg格式");
          return false;
      }
      $('#zzjgfile-list').html(fileNames);
      return true;      
    });
	
	$('#swdjfile').on('change', function() {
      var fileNames = '';
      $.each(this.files, function() {
        fileNames += '<span class="am-badge">' + this.name + '</span> ';
      });
      var filepath = $("input[name='swdjfile']").val();
      var extStart = filepath.lastIndexOf(".");
      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
          alert("图片限于bmp,png,gif,jpeg,jpg格式");
          return false;
      }
      $('#swdjfile-list').html(fileNames);
      return true;      
    });
	
	$('#qyzzfile').on('change', function() {
	      var fileNames = '';
	      $.each(this.files, function() {
	        fileNames += '<span class="am-badge">' + this.name + '</span> ';
	      });
	      var filepath = $("input[name='qyzzfile']").val();
	      var extStart = filepath.lastIndexOf(".");
	      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
	          alert("图片限于bmp,png,gif,jpeg,jpg格式");
	          return false;
	      }
	      $('#qyzzfile-list').html(fileNames);
	      return true;      
	    });
	
	$('#wtzmfile').on('change', function() {
	      var fileNames = '';
	      $.each(this.files, function() {
	        fileNames += '<span class="am-badge">' + this.name + '</span> ';
	      });
	      var filepath = $("input[name='wtzmfile']").val();
	      var extStart = filepath.lastIndexOf(".");
	      var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	      if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
	          alert("图片限于bmp,png,gif,jpeg,jpg格式");
	          return false;
	      }
	      $('#wtzmfile-list').html(fileNames);
	      return true;      
	    });
	
	function loadImg(){
		var img = $("#logofilename").val();
		if(img!=null&&img!=""){
			$("#demo").append("<img src='" + img + "' width='80' height='50'/>");
		}
		
		var yyzzimg = $("#yyzzfilename").val();
		if(yyzzimg!=null&&yyzzimg!=""){
			$("#yyzzdiv").append("<img src='" + yyzzimg + "' width='80' height='50'/>");
		}
		
		var zzjgimg = $("#zzjgfilename").val();
		if(zzjgimg!=null&&zzjgimg!=""){
			$("#zzjgdiv").append("<img src='" + zzjgimg + "' width='80' height='50'/>");
		}
		
		var swdjimg = $("#swdjfilename").val();
		if(swdjimg!=null&&swdjimg!=""){
			$("#swdjdiv").append("<img src='" + swdjimg + "' width='80' height='50'/>");
		}
		
		var qyzzimg = $("#qyzzfilename").val();
		if(qyzzimg!=null&&qyzzimg!=""){
			$("#qyzzdiv").append("<img src='" + qyzzimg + "' width='80' height='50'/>");
		}
		
		var wtzmimg = $("#wtzmfilename").val();
		if(wtzmimg!=null&&wtzmimg!=""){
			$("#wtzmdiv").append("<img src='" + wtzmimg + "' width='80' height='50'/>");
		}
		
		var szhyimg = $("#szhyfilename").val();
		if(szhyimg!=null&&szhyimg!=""){
			$("#szhydiv").append("<img src='" + szhyimg + "' width='80' height='50'/>");
		}
		
		var jjtpimg = $("#qyjjfilename").val();
		if(jjtpimg!=null&&jjtpimg!=""){
			$("#jjtpdiv").append("<img src='" + jjtpimg + "' width='80' height='50'/>");
		}
	};
	
	function bindselect(){
		var qytype = $('#qytype').val();
		$('#doc-select-1').val(qytype);
	}
})

function ajaxDemoUpload(){
	var fileName=$("#file").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/member/fileUpload',
		secureuri:false,
		fileElementId:'file',
		dataType:'text',
		success:function(data){
			console.log(data);
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#demo").append("<img src='" + name + "' width='80' height='50'/>");
					$("#logofilename").val(name);
					alert("上传成功");
				}
				else{
					alert(status);
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxyyzzUpload(){
	var fileName=$("#yyzzfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/yyzzfileUpload',
		secureuri:false,
		fileElementId:'yyzzfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#yyzzdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#yyzzfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxzzjgUpload(){
	var fileName=$("#zzjgfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/zzjgfileUpload',
		secureuri:false,
		fileElementId:'zzjgfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#zzjgdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#zzjgfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxswdjUpload(){
	var fileName=$("#swdjfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/swdjfileUpload',
		secureuri:false,
		fileElementId:'swdjfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#swdjdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#swdjfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxwtzmUpload(){
	var fileName=$("#wtzmfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/wtzmfileUpload',
		secureuri:false,
		fileElementId:'wtzmfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#wtzmdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#wtzmfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxqyzzUpload(){
	var fileName=$("#qyzzfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/qyzzfileUpload',
		secureuri:false,
		fileElementId:'qyzzfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#qyzzdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#qyzzfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxszhyUpload(){
	var fileName=$("#szhyfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/szhyfileUpload',
		secureuri:false,
		fileElementId:'szhyfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#szhydiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#szhyfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}

function ajaxjjtpUpload(){
	var fileName=$("#jjtpfile").val();
	if(fileName==""){
		alert("请选择上传的文件");
		return;
	}
	
	$.ajaxFileUpload({
		url:'/api/member/jjtpfileUpload',
		secureuri:false,
		fileElementId:'jjtpfile',
		dataType:'text',
		success:function(data){
			if(data!=null){
				var status = data.substring(data.indexOf("message")+10,data.indexOf('"}'));
				if(status=="Y"){
					var name = data.substring(data.indexOf("fileName")+10,data.lastIndexOf('}'));
					$("#jjtpdiv").append("<img src='" + name + "' width='80' height='50'/>");
					$("#qyjjfilename").val(name);
					alert("上传成功");
				}
				else{
					alert("上传失败");
				}
			}
		},
		error:function(data){
			console.log(data);
			alert("上传失败");
		}
	})
}